import { login } from '@/control/core/api';
export default {
  data() {
    return {
      src: require('assets/public/images/Bitmap.jpg'),
      name: '',
      password: '',
      errLogin: false // 登陆出错提示 TODO: axios 统一错误处理，区分返回
    };
  },
  methods: {
    login(result) {
      if (this.name === '') {
        this.$message({
          message: '请填写用户名或手机号',
          type: 'warning'
        });
        this.$refs.inputName.focus();
      } else if (this.password === '') {
        this.$message({
          message: '请填写用户密码',
          type: 'warning'
        });
        this.$refs.inputPS.focus();
      } else {
        this.errLogin = true;
        login({
          data: {
            accountID: this.name,
            password: this.password
          }
        }).then(data => {
          this.errLogin = false;
          let info = { ...data.result };

          info.isLogin = true;
          this.$store.dispatch('changeUser', info);
          info.role.roleID < 200
            ? this.$router.push('/home')
            : this.$router.push('/index');
        });
      }
    }
  }
};
